package com.yjd.comm.funds.convert;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.yjd.comm.funds.model.FundsRewardModel;
import com.yjd.comm.funds.model.FundsVolumeModel;
import com.yjd.comm.util.DateUtil;

/**
 * <b>description</b>：债权转让数据转换器 <br>
 * <b>time</b>：2014-11-21下午3:25:02 <br>
 * <b>author</b>： ready likun_557@163.com
 */
public class FundsRewordVolumeModelConvert {
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static FundsRewardModel convertReword(FundsRewardModel model)
			throws Exception {
		if (model != null) {
			Map strMap = model.getStrMap();
			strMap.put("type", 1);
			strMap.put("addtimeStr", DateUtil.timestampToDateString(
					model.getAddtime(),
					DateUtil.PATTERN_yyyy_MM_dd_HH_mm));
			strMap.put("endtimeStr", DateUtil.timestampToDateString(
					model.getEndtime(),
					DateUtil.PATTERN_yyyy_MM_dd));
			model.setStrMap(strMap);
		}
		return model;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static FundsVolumeModel convertVolume(FundsVolumeModel model)
			throws Exception {
		if (model != null) {
			Map strMap = model.getStrMap();
			strMap.put("type", 2);
			strMap.put("addtimeStr", DateUtil.timestampToDateString(
					model.getAddtime(),
					DateUtil.PATTERN_yyyy_MM_dd_HH_mm));
			strMap.put("endtimeStr", DateUtil.timestampToDateString(
					model.getEndtime(),
					DateUtil.PATTERN_yyyy_MM_dd));
			model.setStrMap(strMap);
		}
		return model;
	}
	
	public static List<FundsRewardModel> convertRewardModels(
			List<FundsRewardModel> models) throws Exception {
		if (models == null || models.size() == 0) {
			return models;
		}
		FundsRewardModel register = null;
		FundsRewardModel login = null;
		for (FundsRewardModel model : models) {
			if(model.getEvent_id() == 4){
				//签到红包
				if(login==null){
					login = convertReword(model);
					login.getStrMap().put("name", "签到红包");
				}else{
					login.setBalance(login.getBalance()+model.getBalance());
					login.setPrice(login.getPrice()+model.getPrice());
				}
			}else{
				//注册红包
				if(register==null){
					register = convertReword(model);
					register.getStrMap().put("name", "注册红包");
				}else{
					register.setBalance(register.getBalance()+model.getBalance());
					register.setPrice(register.getPrice()+model.getPrice());
				}
			}
			
		}
		List<FundsRewardModel> newModels = new ArrayList<FundsRewardModel>();
		newModels.add(register);
		newModels.add(login);
		return newModels;
	}
	
	public static List<FundsVolumeModel> convertVolumeModels(
			List<FundsVolumeModel> models) throws Exception {
		if (models == null || models.size() == 0) {
			return models;
		}
		for (FundsVolumeModel model : models) {
			convertVolume(model);
		}
		return models;
	}
}
